package cn.edu.zust.se.service.disk.service;

import cn.edu.zust.se.api.clients.FileClient;
import cn.edu.zust.se.api.entity.vo.FileAndFolderVo;
import cn.edu.zust.se.service.disk.mapper.DiskMapper;
import cn.edu.zust.se.api.entity.Disk;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class DiskServiceImpl extends ServiceImpl<DiskMapper, Disk> implements DiskService {
    private final DiskMapper diskMapper;
    private final FileClient fileClient;

    @Override
    public Disk getInfoByUserId(Long userId) {
        LambdaQueryWrapper<Disk> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Disk::getUserId, userId);

        return diskMapper.selectOne(lqw);
    }
    //获取个人网盘的文件
    //主页（最外层级相当于一个文件夹 其id=0）
    //种类type 1为正常文件 2为回收站文件
    @Override
    public FileAndFolderVo getFilesAndFolders(Long folderId ,Integer type) {
        FileAndFolderVo fileAndFolderVo = new FileAndFolderVo();
        fileAndFolderVo.setFiles(fileClient.getFilesByFolderId(folderId,type));
        fileAndFolderVo.setFolders(fileClient.getFoldersByFolderId(folderId,type));
        return fileAndFolderVo;
    }
}
